/**
 * @author: XJC
 * @date: 2023-11-28 10:19
 * @description：storage.manage
 * @update: 2023-11-28 10:19
 */
/**
 * 设置  本地缓存
 */
export function setStorage(key, obj) {
  if (typeof obj === 'string') {
    localStorage.setItem(key, obj);
  } else {
    localStorage.setItem(key, JSON.stringify(obj));
  }
}

/**
 * 获取
 */
export function getStorage(key) {
  let val = localStorage.getItem(key);
  try {
    return JSON.parse(val);
  } catch (e) {
    return val;
  }
}

/**
 * 删除， 如果不传值，删除所有
 */
export function clearStorage(key) {
  if (key) {
    localStorage.removeItem(key);
  } else {
    localStorage.clear();
  }
}
